﻿// -----------------------------------------------------------------------
// <copyright file="SampleImage.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Pattern_package.Create_Correct_Pattern
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class SampleImage
    {
       public double[,] valueOfPixelInImage;
        public Bitmap CreateSampleImage(int width,int height,int numberOfClass,NormalDistrubution[] DataForEachClass)
        {
            int RangeOfX = this.CalcuRangeForEachClass(width, numberOfClass);
            Bitmap sampleImage = new Bitmap(width, height);
            valueOfPixelInImage = new double[width, height];
            Random newRand1 = new Random();
            Random newRand2 = new Random();
            double rand1, rand2;
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
               
                    rand1 = newRand1.NextDouble();
                    rand2 = newRand2.Next(0,1);
                    valueOfPixelInImage[i,j] = Math.Sqrt(-2 * Math.Log(rand1, Math.E)) * .5 * Math.Cos(2 * Math.PI * rand2);
                    for (int k = 1; k <= numberOfClass; k++)
                    {
                        if (i <= (k * RangeOfX) - 1)
                        {
                            valueOfPixelInImage [i,j]= (double)((valueOfPixelInImage[i, j] * DataForEachClass[k - 1].sigma) + DataForEachClass[k - 1].mean);
                            int col = (int)valueOfPixelInImage[i, j];
                            sampleImage.SetPixel(i, j, Color.FromArgb(col,col,col));
                            break;
                        }
                    }
                }
            }
                return sampleImage;
        }
        public void CalcvalueOfPixelInImage(Bitmap img)
        {
            valueOfPixelInImage = new double[img.Width, img.Height];
            for (int i = 0; i < img.Height; i++)
            {
                for (int j = 0; j < img.Width; j++)
                {
                    Color c = img.GetPixel(j, i);
                    valueOfPixelInImage[j, i] = (double)(c.R);
                }
            }
        }
        private int CalcuRangeForEachClass(int width, int numberOfClass)
        {
            return width / numberOfClass;
        }
    }
}
